﻿#ifndef _FIELD_H_H_
#define _FIELD_H_H_

#include "udatabase/interface/ifield.h"
#include "kernel/variant.h"
#include "udatabase/dll_cfg.h"

namespace FD
{
	namespace Utility
	{
		namespace DB
		{
			///<summary>
			///字段构造类
			///</summary>
			class FD_DB_Export CField : public FD::Utility::DB::Interface::IField
			{
			public:
				friend class CFieldFactory;
			public:
				/// <summary>
				/// 默认析构函数
				/// </summary>
				/// <returns></returns>
				~CField();
				/// <summary>
				/// 获取字段名称
				/// </summary>					
				/// <returns>字段名称</returns>
				virtual String getName() const;
				/// <summary>
				/// 获取字段别名
				/// </summary>					
				/// <returns>字段别名</returns>
				virtual String getAliasName() const;
				/// <summary>
				/// 获取字段类型
				/// </summary>
				/// <returns>字段类型</returns>
				virtual FD::Utility::DB::Interface::FieldType getFieldType() const;
				/// <summary>
				/// 获取字段大小，一般用于FD::Kernel::FdUnicodeString类型
				/// </summary>
				/// <returns>字段大小</returns>
				virtual UINT32 getSize() const;
				/// <summary>
				/// 获取字段精度，一般用于Real类型
				/// </summary>
				/// <returns>字段精度</returns>
				virtual UINT32 getPrecision() const;
				/// <summary>
				/// 获取字段描述
				/// </summary>
				/// <returns>字段描述</returns>
				virtual String getDescription() const;
				/// <summary>
				/// 判断是否必需字段
				/// </summary>
				/// <returns>是，返回true；否则，返回false</returns>
				virtual bool isRequest() const;
				/// <summary>
				/// 判断是否支持编辑，一般情况下，不允许编辑。
				/// </summary>
				/// <returns>是，返回true;否则，返回false</returns>
				virtual bool canEdit() const;
				/// <summary>
				/// 判断是否支持删除，一般情况下，必需字段不允许删除。
				/// </summary>
				/// <returns>是，返回true；否则，返回false</returns>
				virtual bool canDelete() const;
				/// <summary>
				/// 判断是否支持空值。
				/// </summary>
				/// <returns>是，返回true；否则，返回false</returns>
				virtual bool canNull() const;
				/// <summary>
				/// 设置字段别名
				/// </summary>
				/// <param name="value">字段别名</param>
				/// <returns></returns>
				virtual void setAliasName(const FD::Kernel::FdUnicodeString& name);
				/// <summary>
				/// 设置字段大小
				/// </summary>
				/// <param name="value">字段大小</param>					
				/// <returns></returns>
				virtual void setSize(UINT32 value);
				/// <summary>
				/// 设置字段精度
				/// </summary>
				/// <param name="value">字段精度</param>
				/// <returns></returns>
				virtual void setPrecision(UINT32 value);
				/// <summary>
				/// 设置字段描述
				/// </summary>
				/// <param name="description">字段描述</param>
				/// <returns></returns>
				virtual void setDescription(const FD::Kernel::FdUnicodeString& description);
				/// <summary>
				/// 深度拷贝
				/// </summary>
				/// <param name=""></param>
				/// <returns>拷贝对象</returns>
				virtual FD::Utility::DB::Interface::IField* clone() const;
				/// <summary>
				/// 释放当前字段的内存空间
				/// </summary>
				/// <param name=""></param>
				/// <returns></returns>
				virtual void release();			
				virtual FD::Kernel::FdUnicodeString toXML(bool isSegment) const;
				/// <summary>
				/// 序列化字段信息
				/// </summary>
				/// <param name="stream">流</param>
				/// <param name="hasHead">是否有头信息</param>
				/// <returns></returns>
				virtual void toStream(FD::Kernel::DataStream & stream,bool hasHead/* = true*/) const;
				/// <summary>
				/// 序列化字段信息
				/// </summary>
				/// <param name="stream">流</param>
				/// <returns></returns>
				virtual void toStream(FD::Kernel::DataStream & stream) const{ toStream(stream, true); }
				/// <summary>
				/// 从流中获取只读
				/// </summary>
				/// <param name="stream">流</param>
				/// <returns>字段</returns>
				static FD::Utility::DB::CField* fromStream(FD::Kernel::DataStream & stream);
				/// <summary>
				/// 构造函数
				/// </summary>
				/// <param name="fieldType"></param>
				/// <returns></returns>
				CField(FD::Utility::DB::Interface::FieldType fieldType);
				/// <summary>
				/// 构造函数
				/// </summary>
				/// <param name="fieldName"></param>
				/// <param name="fieldType"></param>
				/// <returns></returns>
				CField(const FD::Kernel::FdUnicodeString& fieldName, FD::Utility::DB::Interface::FieldType fieldType);
				/// <summary>
				/// 设置字段名
				/// </summary>
				/// <param name="name">字段名</param>
				/// <returns></returns>
				virtual void setName(const FD::Kernel::FdUnicodeString& name);
				/// <summary>
				/// 设置字段是否可以为空
				/// </summary>
				/// <param name="value">是否</param>
				/// <returns></returns>
				virtual void setCanNull(bool value);
				/// <summary>
				/// 设置字段是否可以编辑
				/// </summary>
				/// <param name="value"></param>
				/// <returns></returns>
				virtual void setCanEdit(bool value);
				/// <summary>
				/// 设置字段是否可以被删除
				/// </summary>
				/// <param name="value"></param>
				/// <returns></returns>
				virtual void setCanDelete(bool value);
				//virtual void setIsPrimary(bool value);

				/// <summary>
				/// 获取字段默认值
				/// </summary>
				/// <returns>字段描述</returns>
				virtual FD::Kernel::Variant getDefaultValue() const;
				/// <summary>
				/// 设置字段默认值
				/// </summary>
				/// <param name="description">字段描述</param>
				/// <returns></returns>
				virtual void setDefaultValue(const FD::Kernel::Variant& defaultValue);
			protected:
				/// <summary>
				/// 默认构造函数
				/// </summary>
				/// <param name=""></param>
				/// <returns></returns>
				CField();



				static FD::Utility::DB::CField* fromStreamWithVersion1(FD::Kernel::DataStream & stream);

			public:
				/// <summary>
				/// 拷贝构造函数
				/// </summary>
				/// <param name=""></param>
				/// <returns></returns>
				CField(const CField & field);

			private:
				///* 从引擎模块接受的数据 */
				//static FD::Utility::DB::CField* fromBinary(FD::Kernel::IO::DataStream & stream);
				///* 序列化引擎所需数据格式 */
				//void toBinary(FD::Kernel::IO::DataStream & stream) const;

			private:
				/// <summary>
				/// 字段名称。
				/// </summary>
				String mstrName;
				/// <summary>
				/// 字段别名
				/// </summary>
				String mstrAliasName;
				/// <summary>
				/// 字段类型
				/// </summary>
				FD::Utility::DB::Interface::FieldType mnFieldType;
				/// <summary>
				/// 字段大小
				/// </summary>
				UINT32 mnSize;
				/// <summary>
				/// 字段精度
				/// </summary>
				UINT32 mnPrecision;
				/// <summary>
				/// 字段描述
				/// </summary>
				String mstrDescription;
				/// <summary>
				/// 是否必需
				/// </summary>
				bool mbIsRequest;
				/// <summary>
				/// 是否可编辑
				/// </summary>
				bool mbCanEdit;
				/// <summary>
				/// 是否可删除
				/// </summary>
				bool mbCanDelete;
				/// <summary>
				/// 是否可为空
				/// </summary>
				bool mbCanNull;
				/// <summary>
				/// 默认值
				/// </summary>
				FD::Kernel::Variant mdefaultVal;

				friend class CFieldFactory;
			};



		} ////GeoDataset
	} 
} 

#endif //_FIELD_H_H_

